/**
 * 
 */
package com.lehecai.core.api.lottery;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.lottery.LotteryType;
import com.lehecai.core.lottery.PlatformType;
import com.lehecai.core.lottery.RefundPlanStatus;
import com.lehecai.core.util.CoreDateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * @author qatang
 *
 */
public class RefundPlan extends AbstractApiResultBean implements java.io.Serializable{

	private static final long serialVersionUID = -4269148527643355707L;
	public static final String QUERY_PLAN_ID = "plan_id";
	public static final String QUERY_UID = "uid";
	public static final String QUERY_LOTTERY_TYPE = "lottery_type";
	public static final String QUERY_PHASE = "phase";
	public static final String QUERY_CREATED_AT = "create_at";
	public static final String QUERY_REFUNDED_AT = "refund_at";
	public static final String QUERY_REFUND_PLAN_STATUS = "refund_status";
	public static final String QUERY_SOURCE_ID = "source";
	public static final String QUERY_PLATFORM = "platform";

	public static final String SET_REFUNDED_AT = "refund_at";
	public static final String SET_REFUND_PLAN_STATUS = "refund_status";
	public static final String SET_REFUND_AMOUNT = "refund_amount";

	public static final String ORDER_PLAN_ID = "plan_id";
	public static final String ORDER_LOTTERY_TYPE = "lottery_type";
	public static final String ORDER_PHASE = "phase";
	public static final String ORDER_CREATED_AT = "create_at";
	public static final String ORDER_REFUND_AMOUNT = "refund_amount";
	public static final String ORDER_REFUNDED_AT = "refund_at";

	private String planId;			//方案编号
	private LotteryType lotteryType;
	private	String phase;			//彩期编号
	private long uid;

	private RefundPlanStatus refundPlanStatus;//退票方案状态
	private double refundAmount; //退票金额

	private Date createAt;		//方案创建时间
	private Date refundAt;		//方案退票时间

	private long sourceId;			//渠道来源
	private PlatformType platformType; //平台

	public static RefundPlan convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		RefundPlan refundPlan = new RefundPlan();

		refundPlan.planId = getString(object, "plan_id");
		refundPlan.setLotteryType(LotteryType.getItem(getInt(object, "lottery_type")));
		refundPlan.phase = getString(object, "phase");
		refundPlan.uid = getLong(object, "uid");
		refundPlan.setCreateAt(getDate(object, "create_at", CoreDateUtils.DATETIME));
		refundPlan.setRefundAt(getDate(object, "refund_at", CoreDateUtils.DATETIME));
		refundPlan.setRefundPlanStatus(RefundPlanStatus.getItem(getInt(object, "refund_status")));
		refundPlan.refundAmount = getDouble(object, "refund_amount");

		refundPlan.sourceId = getLong(object, "source");
		refundPlan.setPlatformType(PlatformType.getItem(getInt(object,"platform")));

		return refundPlan;
	}
	
	@SuppressWarnings("unchecked")
	public static List<RefundPlan> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<RefundPlan> list = new ArrayList<RefundPlan>();
		for (Iterator iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

	public String getPlanId() {
		return planId;
	}

	public void setPlanId(String planId) {
		this.planId = planId;
	}

	public LotteryType getLotteryType() {
		return lotteryType;
	}

	public void setLotteryType(LotteryType lotteryType) {
		this.lotteryType = lotteryType;
	}

	public String getPhase() {
		return phase;
	}

	public void setPhase(String phase) {
		this.phase = phase;
	}

	public long getUid() {
		return uid;
	}

	public void setUid(long uid) {
		this.uid = uid;
	}

	public RefundPlanStatus getRefundPlanStatus() {
		return refundPlanStatus;
	}

	public void setRefundPlanStatus(RefundPlanStatus refundPlanStatus) {
		this.refundPlanStatus = refundPlanStatus;
	}

	public double getRefundAmount() {
		return refundAmount;
	}

	public void setRefundAmount(double refundAmount) {
		this.refundAmount = refundAmount;
	}

	public Date getCreateAt() {
		return createAt;
	}

	public void setCreateAt(Date createAt) {
		this.createAt = createAt;
	}

	public Date getRefundAt() {
		return refundAt;
	}

	public void setRefundAt(Date refundAt) {
		this.refundAt = refundAt;
	}

	public long getSourceId() {
		return sourceId;
	}

	public void setSourceId(long sourceId) {
		this.sourceId = sourceId;
	}

	public PlatformType getPlatformType() {
		return platformType;
	}

	public void setPlatformType(PlatformType platformType) {
		this.platformType = platformType;
	}
}
